HIVE-29059: SHOW CREATE TABLE ignores all strings after tab character for VIEWs#6563
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes HIVE-29059 where SHOW CREATE TABLE for VIEWs can truncate output after literal tab characters by escaping tab characters in the rendered VIEW DDL, and adds a qtest covering several tab-containing VIEW definitions.
Changes:
- Escape literal tab characters (
\t) inSHOW CREATE TABLEoutput for VIEWs. - Add a new clientpositive qtest that creates/views with tabs in whitespace and string literals and verifies
\tescaping. - Add the corresponding LLAP expected output file for the new qtest.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/create/show/ShowCreateTableOperation.java |
Escapes tab characters in the generated CREATE VIEW statement before writing results. |
ql/src/test/queries/clientpositive/show_create_table_tab_view.q |
New qtest query file exercising tab characters in VIEW definitions and literals. |
ql/src/test/results/clientpositive/llap/show_create_table_tab_view.q.out |
New LLAP golden output validating \t escaping and non-view behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ayushtkn
left a comment
There was a problem hiding this comment.
minor comments, rest looks good
|
Hi @ayushtkn thanks again for the review :) I've addressed all the suggested changes. |
| script_pipe.q,\ | ||
| scriptfile1.q,\ | ||
| select_transform_hint.q,\ | ||
| show_create_table_tab_view.q,\ |
There was a problem hiding this comment.
I don't think this is required, you can add a normal test, adding to these files is required for specific cases when u want LLAP or Tez, else by default it goes to normal CLI driver, drop this and move the q.out
There was a problem hiding this comment.
Understood, thanks!
| String command; | ||
| if (table.isView()) { | ||
| command = ddlObj.getCreateViewCommand(table, desc.isRelative()); | ||
| command = ddlObj.getCreateViewCommand(table, desc.isRelative()).replace("\t", "\\t"); |
There was a problem hiding this comment.
I don't think the solution is correct. After this change, If a user copies this SHOW CREATE TABLE output to recreate the view, the execution will fail with a syntax error.
You can see the side effect directly in the .out file you provided:
CREATE VIEW `showcrt_tab_src_v` AS SELECT `showcrt_tab_src`.`val1`, `showcrt_tab_src`.`val2`, `showcrt_tab_src`.`val3` FROM `default`.`showcrt_tab_src`
\tWHERE `showcrt_tab_src`.`val1`\t= 'a1'
\tAND `showcrt_tab_src`.`val2`\t= 'b1'
There was a problem hiding this comment.
Thanks for catching this, that makes sense. I'll update the fix and replace the with space for maintaining the correct syntax outside of string literals, and escape tabs with \t within the string literals for pattern matching. This should address the truncation without breaking syntax or pattern matching.
…ls with \t and outside string literals with space, updated associated tests
…reate_table_truncates_after_tab
ayushtkn
left a comment
There was a problem hiding this comment.
Thinking again, I think the solution isn't cof
| for (int i = 0; i < sql.length(); i++) { | ||
| char c = sql.charAt(i); | ||
| if (quote == 0) { // outside string literal | ||
| if (c == '\'' || c == '"') { |
There was a problem hiding this comment.
I think hive supports ` as well, can u validate if it works with backtics
There was a problem hiding this comment.
Hi @ayushtkn thanks for pointing this out. I've added tests for column identifiers with ` and tabs, and validated that ` needs to be treated differently from the string literals, since identifiers still need the literal tabs (instead of converting to \t) for pattern matching. Direct replacement with \t or space will fail at pattern matching or lose the original literal tab pattern. Thus removed the changes to sql before writing to DataOutputStream, and added an overload to the existing createFetchTask under BaseSemanticAnalyzer to make sure the sql is not splitted by tabs when reading.
…ing fetch task with SERIALIZATION_LAST_COLUMN_TAKES_REST
|
ayushtkn
left a comment
There was a problem hiding this comment.
LGTM
Thanx @cyanzheng2926 for the work here!!!



What changes were proposed in this pull request?
Addresses the issue for HIVE-29059 when a view is created with actual tabs, the SHOW CREATE TABLE output would truncate all strings after the tab.
Why are the changes needed?
SHOW CREATE TABLE of a view's create comment containing tab characters should correctly display all characters without breaking its original syntax or semantic.
Does this PR introduce any user-facing change?
Yes.
When tab is present in the create view statement, running SHOW CREATE TABLE would truncate the output after the tab. e.g.:
CREATE TABLE t1 (val1 string, val2 string);
CREATE VIEW v1 AS SELECT * FROM t1 WHERE val1 = 'a '; -- There are tabs present at val1<tab>= 'a<tab>1';
SHOW CREATE TABLE v1;
-- This would originally output below:
+----------------------------------------------------+
| createtab_stmt |
+----------------------------------------------------+
| CREATE VIEW
v1AS SELECTt1.val1,t1.val2FROMdefault.t1WHEREt1.val1|+----------------------------------------------------+
After the fix, tabs outside string literals are replaced by explicit space to maintain syntax during copy, and tabs within string literals would be replaced with \t for pattern matching e.g.:
+----------------------------------------------------+
| createtab_stmt |
+----------------------------------------------------+
| CREATE VIEW
v1AS SELECTt1.val1,t1.val2FROMdefault.t1WHEREt1.val1= 'a\t1' |+----------------------------------------------------+
How was this patch tested?
Created show_create_table_tab_view.q which contains testing tab for several cases